package com.gdth.bank.widget;

import java.util.ArrayList;
import java.util.List;

import com.gdth.bank.R;
import com.gdth.bank.R.color;
import com.gdth.bank.widget.BankMenuPopupWindow.onPopupMenuItemClickListener;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

/**
 * 查找 界面显示
 * @author Administrator
 *
 */
public class SearchNotificationWindow extends MenuPopupWindow implements OnClickListener{
	EditText inputContent;
	TextView sureSearch;
	ImageView hideView;
	Context context;
	Spinner spinner;
	int selType = 1;
	
	/**
	* 设置自定义的popupmenu布局
	*/
	public SearchNotificationWindow(Context context, int width, int height) {
		super(LayoutInflater.from(context).inflate(R.layout.popup_search_notification, null), width, height);
		this.context = context;
		setFocusable(false);
		setOutsideTouchable(false);
		
	}


	@Override
	public void initViews() {
		// TODO Auto-generated method stub
		inputContent = (EditText) findViewById(R.id.input_content);
		sureSearch = (TextView) findViewById(R.id.sure_search);
		hideView = (ImageView) findViewById(R.id.hide_view);
		spinner = (Spinner) findViewById(R.id.spinner1);
		 final List<String> datas = new ArrayList<String>();
		 MyAdapter adapter = new MyAdapter(context);
		 datas.add("标题");
		 datas.add("内容");
         spinner.setAdapter(adapter);
         inputContent.setFocusable(true);

         adapter.setDatas(datas);
		spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
			
			@Override
			public void onNothingSelected(AdapterView<?> parent) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
				// TODO Auto-generated method stub
				selType = position+1 ; 
			}
		});
	}

	@Override
	public void initEvents() {
		sureSearch.setOnClickListener(this);
		hideView.setOnClickListener(this);
	}

	@Override
	public void init() {
		
		
	}
	private onSearchListener mOnClickListener;

	public void setOnSearchClickListener(onSearchListener listener) {
		mOnClickListener = listener;
	}

	public interface onSearchListener {
		void onRearch(int type,String key);
		
		void onRearchNoContent();
		
		void onRearchHide();
		
	}

	@Override
	public void onClick(View v) {
		switch(v.getId()) {
		case R.id.sure_search:
			String content = inputContent.getText().toString().trim();
			if(TextUtils.isEmpty(content)) {
				Toast.makeText(context, "查询不能为空", Toast.LENGTH_SHORT);
				return ;
			}
			if(null !=mOnClickListener)
				mOnClickListener.onRearch(selType, content);
			break;
		case R.id.hide_view:
			dismiss();
			break;
		}
	}
	
	 public class MyAdapter extends BaseAdapter {
	        List<String> datas = new ArrayList<String>();
	        Context mContext;
	        public MyAdapter(Context context) {
	            this.mContext = context;
	        }

	        public void setDatas(List<String> datas) {
	            this.datas = datas;
	            notifyDataSetChanged();
	        }

	        @Override
	        public int getCount() {
	            return datas==null?0:datas.size();
	        }

	        @Override
	        public Object getItem(int position) {
	            return datas==null?null:datas.get(position);
	        }

	        @Override
	        public long getItemId(int position) {
	            return position;
	        }

	        @Override
	        public View getView(int position, View convertView, ViewGroup parent) {
	            TextView text = new TextView(context); 
	            text.setText(datas.get(position));
	            text.setTextColor(color.canlendar_text_color);
	            text.setPadding(16, 6, 16, 6);
	            text.setTextSize(16);
	            return text;
	        }

	       
	    }
	
}
